package com.wc.alorithm_blue_bridge._DFS._42点游戏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/10 11:03
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3441382&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 细心， dfs
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 10;
    static int[] map = new int[128];
    static int[] num = new int[N];
    static boolean res = false;

    public static void main(String[] args) {
        for (int i = 1; i <= 9; i++) map['0' + i] = i;
        map['A'] = 1;
        map['J'] = 11;
        map['Q'] = 12;
        map['K'] = 13;
        for (int i = 1; i <= 6; i++) {
            char c = sc.next().charAt(0);
            num[i] = map[c];
        }
        dfs(1, num[1], num[2]);
        out.println(res ? "YES" : "NO");
        out.flush();
    }

    static void dfs(int u, int a, int b) {
        if (res) return;
        if (u == 6) {
            if (a == 42) res = true;
            return;
        }
        dfs(u + 1, a + b, num[u + 2]);
        dfs(u + 1, a - b, num[u + 2]);
        dfs(u + 1, a * b, num[u + 2]);
        dfs(u + 1, a / b, num[u + 2]);
    }
}
class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}